<?php

namespace Hrm\Models;

use Helpers\BaseModel;
use Helpers\Tool;

class Reimburse extends BaseModel
{

    /**
     *
     * @var integer
     */
    public $id;

    /**
     *
     * @var integer
     */
    public $userId;

    /**
     *
     * @var integer
     */
    public $year;

    /**
     *
     * @var integer
     */
    public $month;

    /**
     *
     * @var double
     */
    public $officeIn;

    /**
     *
     * @var double
     */
    public $dailyIn;

    /**
     *
     * @var double
     */
    public $bookIn;

    /**
     *
     * @var double
     */
    public $entertainIn;

    /**
     *
     * @var double
     */
    public $foodIn;

    /**
     *
     * @var double
     */
    public $otherIn;

    /**
     *
     * @var double
     */
    public $totalIn;

    /**
     *
     * @var double
     */
    public $trafficOut;

    /**
     *
     * @var double
     */
    public $layoverOut;

    /**
     *
     * @var double
     */
    public $lodgeOut;

    /**
     *
     * @var double
     */
    public $gasOut;

    /**
     *
     * @var double
     */
    public $otherOut;

    /**
     *
     * @var double
     */
    public $totalOut;

    /**
     *
     * @var double
     */
    public $totalPay;

    /**
     *
     * @var integer
     */
    public $createAt;

    /**
     *
     * @var integer
     */
    public $createBy;

    /**
     * Initialize method for model.
     */
    public function initialize()
    {
        parent::initialize();
    }

    /**
     * Returns table name mapped in the model.
     *
     * @return string
     */
    public function getSource()
    {
        return 'XHHrm_Reimburse';
    }

    /**
     * Allows to query a set of records that match the specified conditions
     *
     * @param mixed $parameters
     * @return Reimburse[]|Reimburse|\Phalcon\Mvc\Model\ResultSetInterface
     */
    public static function find($parameters = null)
    {
        return parent::find($parameters);
    }

    /**
     * Allows to query the first record that match the specified conditions
     *
     * @param mixed $parameters
     * @return Reimburse|\Phalcon\Mvc\Model\ResultInterface
     */
    public static function findFirst($parameters = null)
    {
        return parent::findFirst($parameters);
    }

    public static function getMap()
    {
        return [
            'officeIn'    => '办公用品',
            'dailyIn'     => '日常用品',
            'bookIn'      => '图书',
            'entertainIn' => '餐费/招待',
            'foodIn'      => '食品',
            'otherIn'     => '其他1',
            'totalIn'     => '小计1',
            'trafficOut'  => '交通费',
            'layoverOut'  => '驻外补贴',
            'lodgeOut'    => '住宿',
            'gasOut'      => '油费',
            'otherOut'    => '其他2',
            'totalOut'    => '小计2',
            'totalPay'    => '合计',
        ];
    }

    /**
     * 填充数据
     *
     * @param $data
     * @return Reimburse
     *
     * create by ck 20181229
     */
    public function fill($data)
    {
        $map = array_flip(self::getMap());
        foreach ($map as $target => $field) {
            $this->$field = Tool::getValue($data, $target) ?: 0;
        }
        return $this;
    }
}
